
#ifndef TEXTEDIT_H
#define TEXTEDIT_H

#include "replaceby.h"
#include "config.h"
#include "hspell.h"

#include <QSyntaxHighlighter>

class Word
{
    QString m_word;
    bool m_correct;

public:

};

class SyntaxHighlighter : public QSyntaxHighlighter
{
    HSpell	m_spell;
    QTextCharFormat m_alertFormat;

public:

    SyntaxHighlighter   (QTextDocument * parent);
    ~SyntaxHighlighter();

    void setUnderlineColor (const QColor& color) {
        // préparer le format "souligné en vaguelettes"
        m_alertFormat.setUnderlineColor (color);
        m_alertFormat.setUnderlineStyle (QTextCharFormat::SpellCheckUnderline);
    }
    void highlightBlock (const QString &text);
};


//{{{ file documentation -------------------------------------------------------

/*!
 * @file     textedit.h
 * @brief    dicodor text edition widget class declaration
 */

//}}} --------------------------------------------------------------------------
//{{{ includes / predeclarations -----------------------------------------------

#include "hspell.h"
#include <tools.h>
#include "config.h"

#include <QtGui/QTextDocument>
#include <QStringList>

#include <QPlainTextEdit>
#include <QMenu>
#include <QContextMenuEvent>
#include <QMap>

//}}} --------------------------------------------------------------------------
//{{{ structures ---------------------------------------------------------------
//}}} --------------------------------------------------------------------------
//{{{ .TextEdit ----------------------------------------------------------------

class TextEdit:		public QPlainTextEdit
{
    Q_OBJECT

private:
    QMap <QString, QString>	m_toReplace;
    QByteArray		m_format;
    QString			m_path;
    void			createCharMenu ();
    SyntaxHighlighter* m_syntaxHighlighter;
    HSpell			m_spell;
    QMenu			* m_insertCharMenu;

    enum {
        MenuSuggestion = 0,
        MenuAlwaysReplace,
        MenuAddToDic,
        MenuSkip,
        MenuDelete
    };

public:
    explicit		TextEdit (QWidget * parent = 0);
    ~TextEdit();
    bool			isEmpty () { return document ()->isEmpty (); }
    void			keyPressEvent (QKeyEvent *e);
    void			contextMenuEvent (QContextMenuEvent * event);
    void			normalizeText ();

signals:
    void			message (const QString & msg);
    void			documentIsEmpty (bool b);
    void			documentIsModified (bool b);

public slots:
    bool			open (const QString &path);
    bool			saveAs (const QString &path);
    bool            saveAs (const QString &path, const QByteArray &format);
    void			forceUpdate ();
    void			replaceAll (const QString& bad, const QString& good);
};

//}}} --------------------------------------------------------------------------

#endif // TEXTEDIT_H

